<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||	
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws. 
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.). 
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations). 
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Forum/classes/PhpFox_ComponentForumList.class.php, $Author:  $ */



/** Forums list componment
 * 
 * @package module.forum
 * @version $Id: PhpFox_ComponentForumList.class.php 46 2007-12-14 23:12:21Z phpfoxsv $
 *   
 */
class PhpFox_Mod_Forum_ComponentForumList extends BaseComponent
{

    /** Processing method
     */
	function process()
	{
        $oSrvSec = &App::getModuleService('Account', 'Security');
        /* @var $oSrvSec PhpFox_Mod_Account_ServiceSecurity */
        $oSrvSec->checkPerm('forum', array('read_only', 'full'));
	    
	    $oReq = &App::getRequest();
	    /* @var $oReq Request */
        switch($oReq->getAction())
        {
            case 'select_forum':
                $iId = $oReq->getInt('id');
                if ($iId)
                {
                    App::gotoUrl('public.forum.topics', array('id'=>$iId));
                }
                else
                {
                    App::gotoUrl(); //clear POST
                }
                break;
        }

	    $oSrvForum = &$this->_oModule->getService('Forum');
	    /* @var $oSrvForum PhpFox_Mod_Forum_ServiceForum */
	    
	    $aForums = $oSrvForum->getForumList();
	    
	    //calculate totals, hashes and last post
        $iTotalTopics = 0;
        $iTotalPosts = 0;
        $aForumHash = array();
        foreach($aForums as $aForum)
        {
            $iTotalTopics += $aForum['total_topics'];
            $iTotalPosts  += $aForum['total_posts'];
            $aForumHash[$aForum['forum_id']] = $aForum['forum_title'];
        }

		$oTpl = &$this->_oModule->getTemplate();
		$oTpl->assign(array(
            'aForums'         => $aForums,
            'sForumImagesUrl' => App::getParam('forum.pic.url'),
		    'aForumHash'      => $aForumHash,
		    'iTotalTopics'    => $iTotalTopics,
            'iTotalPosts'     => $iTotalPosts,
		    'dtToday'         => time(),
		));
		$srcHtml = $oTpl->fetch('ForumList.html');
		return $srcHtml;
	}

}
?>